package com.javaclimb.accounting.service.impl;

import com.javaclimb.accounting.dao.UserDao;
import com.javaclimb.accounting.po.Account;
import com.javaclimb.accounting.po.User;
import com.javaclimb.accounting.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {
        return userDao.login(user);
    }


    @Transactional

    @Override
    public void register(User user, Account account) {
        userDao.add(account);
        user.setUserAccId(account.getAccId());
        userDao.register(user);
    }

    @Override
    public List<User> verify(User user) {
        return userDao.verify(user);
    }

    @Override
    public List<User> exists(User user) {
        return userDao.exists(user);
    }

    @Override
    public Long add(Account account) {
        userDao.add(account);
        return account.getAccId();
    }


}
